<template>
    <div class="app-container">
        <el-row>
            <el-col>
                <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                    label-width="68px">
                    <el-form-item label="产品类别" prop="productType">
                        <el-select v-model="queryParams.productType" placeholder="请选择产品类别">
                            <el-option v-for="dict in dict.type.product_type" :key="dict.value" :label="dict.label"
                                :value="dict.value" />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="产品编号" prop="productNo">
                        <el-input v-model="queryParams.productNo" placeholder="请输入产品编号" clearable
                            @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item label="产品名称" prop="productName">
                        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable
                            @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>

                <el-row :gutter="10" class="mb8">
                    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"
                        :columns="columns"></right-toolbar>
                </el-row>

                <el-table :row-style="{ height: '30px' }" :cell-style="{ padding: '0px' }" height="270" border
                    v-loading="loading" :data="qualificationList" @selection-change="handleSelectionChange"
                    highlight-current-row>
                    <el-table-column type="selection" width="55" align="center" />
                    <el-table-column label="序号" type="index" :index="indexMethod" />
                    <el-table-column label="发布时间" align="center" prop="releaseTime" width="100px"
                        v-if="columns[0].visible">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.releaseTime, '{y}-{m}-{d}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="产品类别" align="center" prop="productType" :show-overflow-tooltip="true"
                        v-if="columns[1].visible">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.product_type" :value="scope.row.productType" />
                        </template>
                    </el-table-column>
                    <el-table-column label="产品状态" align="center" prop="productStatus" width="100px"
                        :show-overflow-tooltip="true" v-if="columns[8].visible" />
                    <el-table-column label="审核状态" align="center" prop="examineStatus" width="100px"
                        :show-overflow-tooltip="true" />
                    <el-table-column label="产品编号" align="center" prop="productNo" width="120px"
                        :show-overflow-tooltip="true" v-if="columns[2].visible" />
                    <el-table-column label="产品名称" align="left" prop="productName" :show-overflow-tooltip="true"
                        width="200px" v-if="columns[3].visible" />
                    <el-table-column label="产品规格" align="center" prop="productSpecs" width="350px">
                        <template slot-scope="scope">
                            <div class="truncate-text" :title="formatRemark(scope.row.productSpecs).title"
                                v-if="scope.row.productSpecs !== null">
                                {{ scope.row.productSpecs.substring(0, 4) }}{{ scope.row.productSpecs.length > 10 ?
                    '...' : '' }}
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="创建时间" align="center" prop="creationTime" width="100px"
                        :show-overflow-tooltip="true" v-if="columns[10].visible">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="执行文件" align="center" prop="exeStandard">
                        <template slot-scope="scope">
                            <el-button @click.stop="handlePictureCardPreview(scope.row.exeStandard, exeStandardCode)"
                                size="small" type="text">附件</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column label="样板" align="center" prop="template">
                        <template slot-scope="scope">
                            <el-button @click.stop="handlePictureCardPreview(scope.row.template, businessCode)"
                                size="small" type="text">附件</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getList" />

            </el-col>
        </el-row>

        <!--   履历 附件展示对话框-->
        <el-dialog title="查看附件" :visible.sync="openFileList" width="500px" append-to-body v-if="openFileList">
            <UploadFile :upload-id="uploadId" :business-code="UploadCode"></UploadFile>
        </el-dialog>
        <!--   履历 附件展示对话框-->
        <el-dialog title="查看附件" :visible.sync="resumeFileList" width="500px" append-to-body v-if="resumeFileList">
            <UploadFile :upload-id="uploadId" :business-code="businessCode"></UploadFile>
        </el-dialog>
        <!-- 选择对话框开始 -->
    </div>
</template>

<script>
import { listQualification, listQualificationOrgId, getQualification, delQualification, addQualification, updateQualification, approveStatus, releaseStatus, examine, listQualificationAll, revokeNot, getNo, apply } from "@/api/qualificationInfo/qualification";
import FileView from "@/components/FileView/index"
import { listResume, getResume, delResume, addResume, updateResume } from "@/api/qualificationInfo/Resume";
import { getToken } from "@/utils/auth";
import SelectUser from "../system/role/selectUser.vue";
import MainType from "@/components/MainType/index"
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listType } from "@/api/maintype/type";
import UploadFile from "../upload/index.vue";
import { queryFile, fileRemove } from "@/api/system/file";
export default {
    name: "Qualification",
    dicts: ['product_type', 'product_status', 'customer_industry', 'administrative_area', 'qualification_resume_status'],
    components: { UploadFile, FileView, SelectUser, MainType, Treeselect },
    props: {
        orgId: {
            type: Number,
            default: 0
        },
        supplierId: {
            type: Number,
            default: null
        },
        isOpen: {
            type: Boolean,
            default: false
        },
    },
    data() {
        var validateRadio = (rule, value, callback) => {
            if (value) {
                // 当值为0的时候当做没选择
                if (value === '未审核') {
                    callback(new Error('请选择审核结果'))
                } else {
                    callback();
                }
            } else {
                callback(new Error('请选择审核结果'));
            }
        };
        return {
            orgId: this.$store.state.user.info.orgId,
            companyType: this.$store.state.user.info.companyType,
            productId: null,//父传子使用，高亮展示
            classRead: false,
            //主类别
            typeCode: 'qualification',
            isChange: true,
            typeCodeResume: 'qualification_resume',
            // 遮罩层
            loading: true,
            loadingEnter: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            //修改页面中的序号展示
            index: 0,
            addSign: 0,
            OnlyRead: false,//只读
            // 显示搜索条件
            showSearch: true,
            //附件标志位
            isUpload: false,
            //选择标志位
            changeOpen: false,
            examineList: [],
            productStatusList: [],
            // 总条数
            total: 0,
            //判断是否用自定义的下拉框还是数据字典的下拉框
            addStatus: 1,
            // 资质产品管理表格数据
            qualificationList: [],
            // 企业信息表格数据
            infoList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            //弹出框选择，默认为0
            typeSelect: 0,
            businessCode: 'qualification',
            exeStandardCode: 'exeStandard',
            productManual: 'productManual',
            //统计查看样板和执行标准的附件
            UploadCode: '',
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 15,
                productType: null,
                productNo: null,
                productName: null,
                productStatus: null,
                examineStatus: null,
                classificationId: null,
                organizationName: null
            },
            //产品状态
            op: [{
                value: 1,
                label: '上架'
            }],
            dialogImageUrl: '',
            ImgDig: false,
            //主分类
            options: null,
            //主分类履历
            optionsResume: null,
            // 履历查询参数
            ResumeParams: {
                pageNum: 1,
                pageSize: 15,
                qualificationId: null,
                classificationId: null
            },
            //履历对话框标志
            resumeOpen: false,
            //附件对话框
            openFileList: false,
            resumeFileList: false,
            uploadId: null,
            //履历数据列表
            ResumeList: [],
            //履历总数
            Resumetotal: null,
            // 用户导入参数
            upload: {
                // 是否显示弹出层（用户导入）
                open: false,
                // 弹出层标题（用户导入）
                title: "",
                // 是否禁用上传
                isUploading: false,
                // 是否更新已经存在的用户数据
                updateSupport: 0,
                // 设置上传的请求头部
                headers: { Authorization: "Bearer " + getToken() },
                // 上传的地址
                url: process.env.VUE_APP_BASE_API + "/qualificationInfo/qualification/importData"
            },
            //第二层的查询条件
            queryParamsTwo: {
                pageNum: 1,
                pageSize: 15,
                enterpriseName: null,
                administrativeArea: null,
                enterpriseLabel: null,
                industry: null,
            },
            //外协id
            enterId: [],
            //外协名称集合
            enterName: [],
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                productType: [
                    { required: true, message: '请选择产品类别', trigger: 'change' }
                ],
                productNo: [
                    { required: true, message: '请输入产品编号', trigger: 'blur' }
                ],
                productName: [
                    { required: true, message: '请输入产品名称', trigger: 'blur' }
                ],
                certificateInstitution: [
                    { required: true, message: '请输入发证机构', trigger: 'blur' }
                ],
                productStatus: [
                    { required: true, message: '请选择产品状态', trigger: 'change' }
                ],
                productRemark: [
                    { required: true, message: '请输入产品介绍', trigger: 'blur' }
                ],
                releaseTime: [
                    { required: true, message: '请选择发布时间', trigger: 'change' }
                ],
                template: [
                    { required: true, message: '请上传样板', trigger: 'change' }
                ],
                examineStatus: [
                    { required: true, validator: validateRadio, trigger: "change" },
                ],
                endReason: [
                    { required: true, message: '请输入终止原因', trigger: 'blur', when: (data) => data.sendType === 'termination' },
                ],
                unifiedNo: [
                    { required: true, message: '请输入统一编号', trigger: 'blur' }
                ],
            },
            resumeRules: {
                operateTime: [
                    { required: true, message: '请选择更新时间', trigger: 'change' }
                ],
                operateName: [
                    { required: true, message: '请选择更新人', trigger: 'change' }
                ],
                approveName: [
                    { required: true, message: '请选择审批人', trigger: 'change' }
                ],
                operateContent: [
                    { required: true, message: '请输入更新内容', trigger: 'blur' }
                ]
            },
            // 列信息
            columns: [
                { key: 0, label: `发布时间`, visible: true },
                { key: 1, label: `产品类别`, visible: true },
                { key: 2, label: `产品编号`, visible: true },
                { key: 3, label: `产品名称`, visible: true },
                { key: 4, label: `定价范围`, visible: true },
                { key: 5, label: `发证机构`, visible: true },
                { key: 6, label: `查询网址`, visible: true },
                { key: 7, label: `产品介绍`, visible: true },
                { key: 8, label: `产品状态`, visible: true },
                { key: 9, label: `创建人`, visible: true },
                { key: 10, label: `创建时间`, visible: true },
            ],
            //履历对话框标题
            resumeTitle: null,
            //履历新增或删除标志
            openResumeWX: false,
            formResume: {},
            userType: "1",
            Resign: '1',
            show: null,
            //控制履历附件
            showResume: false
        };
    },
    created() {
        console.log(this.$store.state.user)
        this.orgId = this.$store.state.user.info.orgId;
        this.getList();
        this.listTypeResume();
    },
    methods: {
        //获取树节点数据
        listTypeResume() {
            listType({ typeCode: 'qualification_resume' }).then(res => {
                this.optionsResume = res.data;
            })
        },
        /** 查询资质产品管理列表 */
        getList() {
            this.loading = true;
            this.queryParams.organizationId = this.supplierId;
            this.queryParams.examineStatus = "已发布";
            console.log(this.supplierId)
            listQualificationOrgId(this.queryParams).then(response => {
                this.qualificationList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        handleProductTypeChange(value) {
            getNo(value, this.form.id).then(res => {
                this.form.productNo = res;
            })
        },
        //点击获取主类别树节点
        getNode(data) {
            if (data.parentId != '00000000-0000-0000-0000-000000000000') {
                this.queryParams.classificationId = data.id
            } else {
                this.queryParams.classificationId = null;
            }
            this.getList()
        },
        //履历点击获取主类别树节点
        //履历:树点击事件
        getNodeResume(data) {
            if (data.parentId != '00000000-0000-0000-0000-000000000000') {
                this.ResumeParams.classificationId = data.id
            } else {
                this.ResumeParams.classificationId = null;
            }
            this.getResumeList();
        },
        formatRemark(remark) {
            const displayedText = remark.length > 50 ? remark.substring(0, 80) + '...' : remark;
            const title = remark.length > 50 ? remark.substring(0, 80) + '...' : remark;
            return { displayedText, title };
        },
        // 取消按钮
        cancel() {
            this.$refs.form.resetFields();
            this.isUpload = false;
            this.OnlyRead = false;
            this.open = false;
            this.classRead = false;
            this.reset();
        },
        cancelChange() {
            this.isUpload = true;
            this.changeOpen = false;
        },
        //序号展示
        indexMethod(index) {
            return index + 1;
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                productType: null,
                productNo: null,
                productName: null,
                productPrice: null,
                productSellPrice: null,
                productStatus: null,
                enterpriseId: null,
                enters: null,
                productRemark: null,
                exeStandard: null,
                template: null,
                operateId: null,
                departmentId: null,
                organizationId: null,
                departmentName: null,
                organizationName: null,
                creationTime: null,
                operateTime: null,
                createId: null,
                selectUrl: null,
                userName: null,
                releaseTime: null,
                approve: null,
                classificationId: null,
                uploadFile: null,
                isChange: null,
                examineStatus: null,
                endReason: null,
                productSpecs: null,
                productManual: null,
                unifiedNo: null
            }
            // this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 导入按钮操作 */
        handleImport() {
            this.upload.title = "用户导入";
            this.upload.open = true;
        },
        //上架
        handleListing() {
            const result = this.productStatusList.some(item => item.includes("已上架"));
            if (result) {
                this.$message.error("不能重复上架已上架的产品");
            } else {
                approveStatus(this.ids, "已上架").then(response => {
                    this.$modal.msgSuccess("上架成功");
                    this.getList();
                })
            }
        },
        //下架
        handleShelves() {
            const result = this.examineList.some(item => item.includes("已发布"));
            const status = this.productStatusList.some(item => item.includes("未上架"));
            if (result || status) {
                this.$message.error("不能下架未上架的产品以及已发布的产品");
            } else {
                approveStatus(this.ids, "已下架").then(response => {
                    this.$modal.msgSuccess("下架成功");
                    this.getList();
                })
            }
        },
        //发布
        handleRelease() {
            const result = this.productStatusList.some(item => item === '已上架');
            const status = this.examineList.some(item => item === '已发布')
            if (!result) {
                this.$message.error("需先上架产品才允许发布！")
            } else if (status) {
                this.$message.error("不允许重复发布已发布过的产品！")
            } else {
                releaseStatus(this.ids).then(res => {
                    this.$modal.msgSuccess("发布成功");
                    this.getList();
                })
            }
        },
        // 文件上传中处理
        handleFileUploadProgress(event, file, fileList) {
            this.upload.isUploading = true;
        },
        // 文件上传成功处理
        handleFileSuccess(response, file, fileList) {
            this.upload.open = false;
            this.upload.isUploading = false;
            this.$refs.upload.clearFiles();
            this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
            this.getList();
        },
        /** 下载模板操作 */
        importTemplate() {
            this.download('/qualificationInfo/qualification/importTemplate', {
            }, `资质产品信息导出.xlsx`)
        },
        // 履历表单重置
        resetResume() {
            this.formResume = {
                id: null,
                qualificationId: null,
                operateTime: null,
                operateContent: null,
                status: null,
                operateId: null,
                approveId: null,
                remark: null,
                createId: null,
                creationTime: null,
                uploadFile: null,
                createName: null,
                approveName: null,
                operateName: null,
            };
            this.resetForm("formResume");
        },
        //履历对话框
        handleLvli(row) {
            const id = row.id
            this.ResumeParams.qualificationId = row.id;
            this.getResumeList();
            this.resumeOpen = true;
        },
        //审核
        handleExamine(row, index) {
            this.reset();
            const id = row.id || this.ids
            getQualification(id).then(response => {
                this.form = response.data;
                this.addStatus = 3;
                this.addSign = 3;
                this.index = index + 1;
                this.typeSelect = 2;
                this.form.endReason = null;
                this.OnlyRead = true;
                this.isUpload = true;
                this.open = true;
                this.title = "审核主营产品信息";
            });
        },
        //查看
        handleSelect(row, index) {
            this.reset();
            const id = row.id || this.ids
            getQualification(id).then(response => {
                this.form = response.data;
                this.addStatus = 2;
                this.addSign = 2;
                this.index = index + 1;
                this.typeSelect = 2;
                this.OnlyRead = true;
                if (this.companyType === '2') {
                    //说明是园区
                    this.classRead = true;
                }
                this.isUpload = true;
                this.open = true;
                this.title = "查看主营产品信息";
            });
        },
        //删除
        handleDelete(row) {
            this.$confirm('此操作将删除, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                delQualification(row.id).then(res => {
                    this.$message.success("删除成功");
                    this.getList();
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });
        },
        //撤销审核
        handleRevoke(row) {
            this.$confirm('此操作将撤销审核, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                revokeNot(row.id).then(res => {
                    if (res.code === 200) {
                        this.$message.success("撤销成功");
                        this.getList();
                    } else {
                        this.$message.error("撤销失败");
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });
        },
        //停用
        handleDeactivate(row) {
            this.$confirm('此操作将停用该产品, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                apply(row.id).then(res => {
                    if (res.code === 200) {
                        this.$message.success("停用成功");
                        this.getList();
                    } else {
                        this.$message.error("停用失败");
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });
        },
        //启用
        handleEnable(row) {
            this.$confirm('此操作重新启用该产品, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                apply(row.id).then(res => {
                    if (res.code === 200) {
                        this.$message.success("启用成功");
                        this.getList();
                    } else {
                        this.$message.error("启用成功");
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });
        },
        //关闭履历，刷新树节点
        resetReusumeClose() {
            this.ResumeParams.classificationId = null
            console.log(this.ResumeParams)
        },
        //履历列表
        getResumeList() {

            listResume(this.ResumeParams).then(response => {
                this.ResumeList = response.rows;
                console.log(this.ResumeList)
                this.Resumetotal = response.total;
                this.loading = false;
            });
        },
        /** 新增履历操作 */
        handleAddLvli() {
            this.resetResume();
            this.formResume.qualificationId = this.ResumeParams.qualificationId;
            this.formResume.createName = this.$store.state.user.name;
            this.formResume.creationTime = new Date();
            this.formResume.uploadFile = new Date().getTime();
            this.formResume.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7'

            this.addSign = 0;
            this.typeSelect = 0;
            this.showResume = true;
            this.listTypeResume();
            this.openResumeWX = true;
            this.resumeTitle = "添加";
        },
        /** 修改履历操作 */
        handleUpdateLvli(row, index) {
            this.reset();
            console.log(this.formResume)
            const id = row.id
            this.index = index + 1
            this.typeSelect = 1;
            this.addSign = 1;
            getResume(id).then(response => {
                this.formResume = response.data;
                this.openResumeWX = true;
                this.listTypeResume();
                this.resumeTitle = "修改资质产品履历";
                this.showResume = true;
            });
        },
        /** 提交履历按钮 */
        submitFormResume() {
            this.$refs["formResume"].validate(valid => {
                if (valid) {
                    if (this.formResume.id != null) {
                        updateResume(this.formResume).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.openResumeWX = false;
                            this.showResume = false;
                            this.getResumeList();
                        });
                    } else {
                        console.log(this.formResume)
                        addResume(this.formResume).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.openResumeWX = false;
                            this.showResume = false;
                            this.getResumeList();
                        });
                    }
                }
            });
        },
        //取消履历
        cancelResume() {
            this.openResumeWX = false;
            this.showResume = false;
            this.resetResume();
        },
        //点击选择用户
        selectOpen(type) {
            this.show = type
            this.$refs.select.show();
        },
        //获取用户
        selectUser(userId, userName, phone) {
            if (this.show === '1') {
                this.$set(this.formResume, 'operateName', userName)
                this.$set(this.formResume, 'operateId', userId)
            } else if (this.show === '2') {
                this.$set(this.formResume, 'createName', userName)
                this.$set(this.formResume, 'createId', userId)
            } else if (this.show === '3') {
                this.$set(this.formResume, 'approveName', userName)
                this.$set(this.formResume, 'approveId', userId)
            }
        },
        // 提交上传文件
        submitFileForm() {
            this.$refs.upload.submit();
        },
        //确认按钮，关闭第二层，并且获取到指定的数据
        getEnter() {
            this.innerVisible = false;
            //拼接id,赋值给外协id，传入后端
            if (this.enterId.length === 1 && this.enterName.length === 1) {
                this.form.enterpriseId = this.enterId[0];
                this.form.enters = this.enterName[0];
            } else {
                this.form.enterpriseId = this.enterId.join(',');
                this.form.enters = this.enterName.join(',');
            }
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.queryParams.classificationId = null
            this.queryParams.productStatus = null
            this.queryParams.productName = null
            this.queryParams.productType = null
            this.queryParams.productNo = null
            this.queryParams.examineStatus = null
            this.queryParams.organizationName = null
            this.reset();
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.examineList = selection.map(item => item.examineStatus)
            this.productStatusList = selection.map(item => item.productStatus)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        // 多选框选中数据
        handleSelectionChangeEnter(selection) {
            this.enterId = selection.map(item => item.enterpriseId)
            this.enterName = selection.map(item => item.enterpriseName)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 搜索按钮操作 */
        handleQueryEnter() {
            this.queryParams.pageNum = 1;
            this.getListEnter();
        },
        //企业重置
        resetQueryEnter() {
            this.resetForm("queryFormEnter");
            this.handleQueryEnter();
        },

        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.title = "添加资质产品管理";
            this.form.exeStandard = new Date().getTime();
            this.form.template = new Date().getTime() + 20;
            this.form.productManual = new Date().getTime() + 40;
            this.isChange = true;
            this.typeSelect = 0;
            this.addStatus = 1;
            this.form.isChange = 0;
            if (this.queryParams.classificationId != null) {
                this.form.classificationId = this.queryParams.classificationId;
            } else {
                this.form.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7';
            }
            this.form.userName = this.$store.state.user.name;
            this.form.creationTime = new Date();
            this.addSign = 0;
            this.isUpload = true;
            this.open = true;
        },
        getFile(data) {
            console.log(JSON.stringify(data))
        },
        //选择按钮
        handleChange() {
            this.changeOpen = true;
            this.isUpload = false;
        },
        /** 修改按钮操作 */
        handleUpdate(row, index) {
            this.reset();
            const id = row.id || this.ids
            getQualification(id).then(response => {
                this.form = response.data;
                console.log(this.form)
                this.addStatus = 2;
                this.isChange = true;
                this.addSign = 1;
                this.index = index + 1;
                this.typeSelect = 1;
                this.isUpload = true;
                this.open = true;
                this.title = "修改资质产品管理";
            });
        },
        //子传父
        changeProduct(data) {
            this.$refs.form.resetFields();
            this.form = data;
            this.form.id = null;
            this.form.isChange = 1;
            this.changeOpen = false;
            this.OnlyRead = true;
            this.typeSelect = 1;
            this.form.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7';
            this.isUpload = true;
        },
        //取消选择
        closeProduct() {
            this.$refs.form.resetFields();
            this.form = {};
            this.changeOpen = false;
            this.OnlyRead = false;
            this.typeSelect = 0;
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null && this.addStatus === 2) {
                        queryFile(this.form.template, "qualification").then(res => {
                            var dataFile = res.data
                            if (dataFile.length == 0) {
                                this.$modal.msgError("请上传样板！");
                            } else {
                                updateQualification(this.form).then(response => {
                                    this.$modal.msgSuccess("修改成功");
                                    this.open = false;
                                    this.getList();
                                });
                            }
                        })
                    } else if (this.form.id != null && this.addStatus === 3) {
                        examine(this.form).then(res => {
                            this.$modal.msgSuccess("审核成功");
                            this.open = false;
                            this.getList();
                        })
                    }
                    else {
                        queryFile(this.form.template, "qualification").then(res => {
                            var dataFile = res.data
                            if (dataFile.length == 0) {
                                this.$modal.msgError("请上传样板！");
                            } else {
                                addQualification(this.form).then(response => {
                                    this.$modal.msgSuccess("新增成功");
                                    this.open = false;
                                    this.OnlyRead = false;
                                    this.isChange = false;
                                    this.getList();
                                });
                            }
                        })
                    }
                }
            });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('qualificationInfo/qualification/export', {
                ...this.queryParams
            }, `qualification_${new Date().getTime()}.xlsx`)
        },
        handlePictureCardPreview(id, code) {
            this.uploadId = id;
            this.UploadCode = code;
            this.openFileList = true;
        },
        handlePictureCardPreviewResume(id) {
            this.uploadId = id;
            this.resumeFileList = true;
        }
    }
};
</script>
<style>
#inp {
    width: 202.5px;
}

.myTooltips {
    width: 50%;
}

.ellipsis-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.red-text {
    color: red;
}
</style>
